/**
 * Tooltip
 */
(function() {
	
	var scripts = document.getElementsByTagName("script")
	var currentScriptPath = scripts[scripts.length-1].src;
	app.directive('zTooltip',['$http','$compile',function($http,$compile) {
		return {
			restrict:'A',
			scope: {
				content:'@',
				show:'@'
			},
			link: function(scope,element,attrs,controller){
//				scope.$watch('content',function(newValue,oldValue){
//					element.tooltip('destroy');
//					if(newValue!=''&&newValue!=undefined){
//						$http.get(currentScriptPath.substring(0, currentScriptPath.lastIndexOf('/') + 1) +"tooltip.html").success(function(data, status, headers, config) {
//							var contentHTML = $compile(data)(scope);
//							var option = {
//									trigger:"manual",
//									placement:"top",
//									content:contentHTML,
//									html:true,
//									title:scope.content
//							};
//							$(element).tooltip(option).tooltip('show');
//						}).error(function(data, status, headers, config) {
//							console.log("加载模板模板失败");
//						});
//					}
//				});
				scope.$watch('show',function(newValue,oldValue) {
					if(newValue==true||newValue=="true") {
						$http.get(currentScriptPath.substring(0, currentScriptPath.lastIndexOf('/') + 1) +"tooltip.html").success(function(data, status, headers, config) {
							var contentHTML = $compile(data)(scope);
							var option = {
									trigger:"manual",
									placement:"top",
									content:contentHTML,
									html:true,
									title:scope.content
							};
							$(element).tooltip(option).tooltip('show');
						}).error(function(data, status, headers, config) {
							console.log("加载模板模板失败");
						});
					} else {
						element.tooltip('destroy');
					}
				});
				
			}
		};
	}]);

}());
